<?php
namespace App;
use Session;
use Illuminate\Database\Eloquent\Model;
use DB;
class Cart_Home extends Model
{
	public $timestamps = false;
    //列表查询
	public function lists($uid){
		$datas=DB::table('cart')->where('status',0)->where('uid',$uid)->get();
		return array_map('get_object_vars', $datas);
	}
    //列表查询
    public function cart_del($cart_id){
        return DB::table('cart')->where('cart_id',$cart_id)->update(['status'=>1]);
         
    }
    //列表查询(特定字段名)
    public function getSome($uid){
        $datas=DB::table('cart')->where('status',0)->where('uid',$uid)->select('uid','goods_id','goods_name','goods_sn','buy_num','goods_price','goods_img','goods_sum_price','product_attr_id')->get();
        return array_map('get_object_vars', $datas);
    }
    //修改库存数
	public function addNumber($goods_id,$buy_number,$cart_id,$user_id){
        $res=DB::table('cart')->where('goods_id',$goods_id)->where('uid',$user_id)->where('cart_id',$cart_id)->update(['buy_num'=>$buy_number]);
        if($res){
            return true;
        }
        return false;
    }
    //获取商品单价
    public function getprice($goods_id,$cart_id,$user_id){
    	$res=DB::table('cart')->where('goods_id',$goods_id)->where('uid',$user_id)->where('cart_id',$cart_id)->select('goods_price')->get();
        return array_map('get_object_vars',$res);
    }
    //修改商品总价
    public function add_price_sum($goods_id,$cart_id,$price_sum){
    	$res=DB::table('cart')->where('goods_id',$goods_id)->where('cart_id',$cart_id)->update(['goods_sum_price'=>$price_sum]);
        if($res){
            return true;
        }
        return false;
    }
    //获取当前用户所有的数据
    public function getall($uid){
    	$datas=DB::table('cart')->where('status',0)->where('uid',$uid)->select('goods_sum_price')->get();
		return array_map('get_object_vars', $datas);
    }
   
    
}
